package Kamera;

import javax.media.j3d.Transform3D;
import javax.media.j3d.View;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

/**
 * 
 * @author Eva Thieme
 *
 */
public class MyKam {

	private Transform3D camTransform;
	private View view;
	private Point3d mitte = new Point3d(0.0f, 5.5f, 0.0f);
	private Vector3d up = new Vector3d(0.0,1.0,0.0);
	private Point3d position = new Point3d(6, 6, 6);
	
	public MyKam(View myView) {
		view = myView;
		view.setCompatibilityModeEnable(true);		
		camTransform = new Transform3D();
			
		Transform3D camProjection = new Transform3D();
		camProjection.perspective(1.2f, 1, 0.1, 100.0);
		
		view.setLeftProjection(camProjection);
	}
	
	public void setKamPos(int i){
		if (i==1){
			position = new Point3d(1, 7, 9);
		} else {
			position = new Point3d(-1, 7, -9);
		}
		setKam();
	}
	
	public void changePosition(String richtung) {
		double schritt = 0.1;
		double x = position.x;
		double y =  position.y;
		double z = position.z;
		if (richtung.equals("oben")){
			y = y +schritt;
			
		} else if (richtung.equals("unten")) {
			y = y -schritt;
			
			
		} else if (richtung.equals("links")){
			
			if ((x>=0) && (z>=0)) {
				x = x-schritt;
				z = z+schritt;
			} else if ((x>=0) && (z<0)) {
				x = x+schritt;
				z = z+schritt;
			} else if ((x<0)&&(z>=0)) {
				x = x-schritt;
				z = z-schritt;
			} else if ((x<0)&&(z<0)) {
				x = x+schritt;
				z = z-schritt;
			} else {
				//nix
			}
			
		} else if (richtung.equals("rechts")) {
			
			if ((x>=0) && (z>=0)) {
				x = x+schritt;
				z = z-schritt;
			} else if ((x>=0) && (z<0)) {
				x = x-schritt;
				z = z-schritt;
			} else if ((x<0)&&(z>=0)) {
				x = x+schritt;
				z = z+schritt;
			} else if ((x<0)&&(z<0)) {
				x = x-schritt;
				z = z+schritt;
			} else {
				//nix
			}
			
			
			
			
		} else {
			//nix
		}
		
		if (y < 6)y = 6;
		if (y>12) y=12;
		if (x<(-9)) x=-9;
		if (x>9) x=9;
//		if ((0<x) && (x<5)) x=5;
//		if ((0>x) && (x>-5)) x=-5;
		if (z<(-9)) z=-9;
		if (z>9) z=9;
//		if ((0<z) && (z<5)) z=5;
//		if ((0>z) && (z>-5)) z=-5;
		
		position.setX(x);
		position.setY(y);
		position.setZ(z);
		setKam();
	}
	
	private void setKam(){
//		System.out.println(position.x + " "+position.y + " "+ position.z);
		camTransform.lookAt(position, mitte, up);
		view.setVpcToEc(camTransform);
	}
}
